<template>
  <div>
    <home-search></home-search>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh" success-text="刷新成功">
      <home-swip></home-swip>
      <home-layout></home-layout>
      <home-tab></home-tab>
    </van-pull-refresh>
    <home-tabbar></home-tabbar>
  </div>
</template>

<script>
  import Search from 'home/components/Search'
  import Swip from 'home/components/Swip'
  import Tab from 'home/components/Tab'
  import Layout from 'home/components/Layout'
  import BottomTabbar from 'home/components/BottomTabbar'
  import GoodsCard from 'home/components/Goodscard'

  import axios from 'axios'
  import Vue from 'vue';
  import { PullRefresh } from 'vant';

  Vue.use(PullRefresh);
  export default{
    name:'Home',
    components:{
      HomeSearch:Search,
      HomeSwip:Swip,
      HomeLayout:Layout,
      HomeTab:Tab,
      HomeTabbar:BottomTabbar,
      HomeCard:GoodsCard
    },
    data() {
      return {
        count: 0,
        isLoading: false
      }
    },
    mounted:function(){
      // 页面打开就会请求数据
      this.getHomeInfo()
    },
    methods: {
      onRefresh() {
        setTimeout(() => {
          // 刷新业务逻辑处理
          this.isLoading = false;
          // 刷新重新请求数据
           this.getHomeInfo()
        }, 500);
      },
      getHomeInfo:function(){
              this.$axios({
                methods:"get",
                url:'api/data.json',
              })
              .then(this.getHomeInfoScc)
              .catch(error => console.log(error, "error")); // 失败的返回
        },
        getHomeInfoSucc(res){
          res=res.data
          // isSuccess后端获取成功返回的标识符
          // HomeInfo后端获取的数据
          if(res.isSuccess && res.data){
            console.log(res.data)
          }
        }
      },
  }
</script>

<style>
</style>
